if SERVER then
	AddCSLuaFile("shared.lua")
end

if CLIENT then
	SWEP.PrintName = "Keys"
	SWEP.Slot = 1
	SWEP.SlotPos = 1
	SWEP.DrawAmmo = false
	SWEP.DrawCrosshair = true

	SWEP.FrameVisible = false
end

function SWEP:Initialize()
	if SERVER then self:SetWeaponHoldType("normal") end
end

function SWEP:Deploy()
	if SERVER then
		self.Owner:DrawViewModel(false)
		self.Owner:DrawWorldModel(false)
	end
end

SWEP.Author = "Ploo"
SWEP.Instructions = "Left click to lock. Right click to unlock"
SWEP.Contact = ""
SWEP.Purpose = ""

SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix  = "rpg"

SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.LockSound = "doors/door_latch3.wav"
SWEP.UnlockSound = "doors/door_latch3.wav"
SWEP.KnockSound = "physics/wood/wood_crate_impact_hard2.wav"
SWEP.KnockHardSound = "physics/wood/wood_crate_impact_hard3.wav"

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = ""

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = ""


function SWEP:PrimaryAttack()
	if CLIENT then return end
	local ply = self.Owner
	local tr = self.Owner:GetEyeTrace()
	local ent = self.Owner:GetEyeTrace().Entity
	
	if not ent:IsDoor() then return end
	
	if ent:IsOwner(ply) or ent:IsCoOwner(ply) then
		ent:Fire("lock", "", 0)
		self.Owner:EmitSound(self.LockSound)
	else
		self.Owner:EmitSound(self.KnockSound)
	end
	self.Weapon:SetNextPrimaryFire(CurTime() + 1)
end

function SWEP:SecondaryAttack()
	if CLIENT then return end
	local ply = self.Owner
	local tr = self.Owner:GetEyeTrace()
	local ent = self.Owner:GetEyeTrace().Entity
	
	if not ent:IsDoor() then return end
	
	if ent:IsOwner(ply) or ent:IsCoOwner(ply) then
		ent:Fire("unlock", "", 0)
		self.Owner:EmitSound(self.UnlockSound)
	else
		self.Owner:EmitSound(self.KnockHardSound)
	end
	self.Weapon:SetNextPrimaryFire(CurTime() + 1)
end

function SWEP:Reload()
	if CLIENT then return end
	
end